import { TOKEN_TIME, TOKEN_TIME_VALUE } from "./constant";
import local from "./localStorage";

// 登录时设置token时间
const setTokenTime = () => {
  local.set(TOKEN_TIME, Date.now());
};

// 获取token时间
const getTokenTime = () => {
  return local.get(TOKEN_TIME);
};

// 检测是否过期
const diffTokenTime = () => {
  const currentTime = Date.now();
  const tokenTime = getTokenTime();
  return currentTime - tokenTime > TOKEN_TIME_VALUE;
};

export { setTokenTime, getTokenTime, diffTokenTime };
